import userApi from '@/api/userApi'
import type { MenuItem } from '@/types/munuType'
import { getTreeData } from '@/utils'

export interface IAuthData {
  buttonList: string[]
  menuList: MenuItem[]
  menuPath: string[]
}

export default async function AuthLoader(): Promise<IAuthData> {
  const res = await userApi.getPermissionList()
  const menuPath = getTreeData(res.menuList)
  return {
    buttonList: res.buttonList,
    menuList: res.menuList,
    menuPath
  }
}
